package com.clear.proxy.staticProxy.securityProxy;

/**
 * 代理对象
 */
public class SecurityProxy implements SensitiveDataQuery{
    private final SensitiveDataQuery sensitiveDataQuery;    // 组合被代理对象
    private final UserAuthenticator userAuthenticator;

    public SecurityProxy(SensitiveDataQuery sensitiveDataQuery, UserAuthenticator userAuthenticator) {
        this.sensitiveDataQuery = sensitiveDataQuery;
        this.userAuthenticator = userAuthenticator;
    }

    @Override
    public String queryData(String userId) {
        if (userAuthenticator.hasPermission(userId)){
            return sensitiveDataQuery.queryData(userId);
        }
        return "Access Denied: Insufficient permission for user" + userId;
    }
}
